package com.qf.hero;

public class BattleManager {

    /**
     * kof 机制3v3
     * 每轮双方各派一个英雄出场，获胜的英雄继续留下来战斗
     * 战败的英雄要派出下一位英雄出场
     * 直到某一所有英雄都战败，游戏结束
     *
     * @param team1
     * @param team2
     */
    public static void pk3v3(Fightable[] team1, Fightable[] team2) {

        int teamNum1 = 0;
        int teamNum2 = 0;
        while (teamNum1 < 3 && teamNum2 < 3) {

            System.out.println("=====NEW PK!====");
            pk(team1[teamNum1], team2[teamNum2]);

            if (team1[teamNum1].isAlive()) {
                teamNum2++;
            } else if (team2[teamNum2].isAlive()) {
                teamNum1++;
            } else {
                System.out.println("error!");
                return;
            }

            System.out.println("===============");

        }

        if (teamNum1 ==3){
            System.out.println("team2 获胜!");
        }else {
            System.out.println("team1 获胜!");
        }


    }


    /**
     * 1v1 两个人战斗
     *
     * @param player1
     * @param player2
     */
    public static void pk(Fightable player1, Fightable player2) {

        System.out.println("Battle star!!");

        int count = 0;

        // 当两个选手都 活着时，就继续进行游戏
        while (player1.isAlive() && player2.isAlive()) {
            System.out.println("round:" + (++count));
            // player1 先攻击
            if (player1.isAlive()) {
                player1.fight(player2);
            }

            // player2 攻击
            if (player2.isAlive()) {
                player2.fight(player1);
            }

            player1.printInfo();
            player2.printInfo();
        }

        // 打印获胜玩家
        if (player1.isAlive()) {
            System.out.println("获胜的是：team1");
        } else {
            System.out.println("获胜的是：team2");
        }

    }

}
